use tauri::{App, Manager};
use window_vibrancy::{self, NSVisualEffectMaterial};
use window_shadows::set_shadow;
#[cfg(target_os = "macos")]
use crate::WindowExt;

/// setup
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {

    let win = app.get_window("main").unwrap();
    let login = app.get_window("login").unwrap();
    #[cfg(target_os = "windows")]
    win.set_decorations(false).unwrap();

    #[cfg(target_os = "windows")]
    login.set_decorations(false).unwrap();
    // 仅在 macOS 下执行
    #[cfg(target_os = "macos")]
    window_vibrancy::apply_vibrancy(&win, NSVisualEffectMaterial::HudWindow,None,Some(10.0))
        .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

    #[cfg(target_os = "macos")]
    window_vibrancy::apply_vibrancy(&login, NSVisualEffectMaterial::HudWindow,None,Some(10.0))
        .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

    // 仅在 windows 下执行
    #[cfg(target_os = "windows")]
    window_vibrancy::apply_acrylic(&win, Some((18, 18, 18, 125)))
        .expect("Unsupported platform! 'apply_blur' is only supported on Windows");

    #[cfg(target_os = "windows")]
    window_vibrancy::apply_acrylic(&login, Some((18, 18, 18, 125)))
        .expect("Unsupported platform! 'apply_blur' is only supported on Windows");

    #[cfg(any(windows, target_os = "macos"))]
    set_shadow(&login,true).unwrap();

    #[cfg(any(windows, target_os = "macos"))]
    set_shadow(&win,true).unwrap();

    #[cfg(target_os = "macos")]
    win.set_transparent_titlebar(true,false);

    #[cfg(target_os = "macos")]
    login.set_transparent_titlebar(true,false);


    login.show().unwrap();


    Ok(())
}
